<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mini.css/3.0.1/mini-default.min.css">
    <title>你切换一下页面试试嘛</title>
    <style>
        .toast{
            --toast-back-color: rgb(127,186,218);
            bottom: 85%;
        }
    </style>
</head>

<body>
    <span class="toast" id=toast>切换一下标签页试试？</span>


    <script>
        // 可以用来校正离开页面，处于后台中的定时器的时间，
        let leaveTime = null; // 记录离开页面的时间
        let backTime = null;  // 记录回到页面的时间

        let toast = document.getElementById('toast')

        document.addEventListener('visibilitychange', function () {
            if (document.hidden) {
                document.title = '别走嘛(*꒦ິ⌓꒦ີ)';
                leaveTime = new Date().getTime()
                toast.classList.remove('toastShow')
            }
            else {
                document.title = '你回来啦(⑅˃◡˂⑅)'
                backTime = new Date().getTime()
                // alert(`你离开了${(backTime - leaveTime) / 1000}秒`)
                toast.innerText = `在你离开的${(backTime - leaveTime) / 1000}秒里，我一直在想你`;
            }
        });
    </script>
</body>

</html>